package com.aihuishou.controller;


import com.aihuishou.pojo.AccountConversion;
import com.aihuishou.service.AccountConversionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 三方账户转换表 前端控制器
 * </p>
 *
 * @author JinX
 * @since 2021-03-23
 */
@RestController
@RequestMapping("/accountConversion")
public class AccountConversionController {

    @Autowired
    private AccountConversionService service;
    @Autowired
    private RedisCacheManager cacheManager;

    @Cacheable(cacheNames = "accountConversion", key = "#id")
    @GetMapping("findById/{id}")
    public AccountConversion findById(@PathVariable("id") Long id) {
        return service.getById(id);
    }

    @GetMapping("getCache/{id}")
    public AccountConversion getCache(@PathVariable("id") Long id) {
        Cache cache = cacheManager.getCache("accountConversion");
        System.out.println(cache.getName());
        AccountConversion accountConversion = cache.get(id, AccountConversion.class);
        System.out.println("accountConversion = " + accountConversion);
        return accountConversion;
    }

}

